
import { createStore } from 'vuex'

import createPersistedState from "vuex-persistedstate";
const store = createStore({
  state:
  {
    color: "#C9C9C9",
    bodycolor: "#292827",
    cat_id:0,
    order_price:0,
    role: []

  },

  mutations: {
    // 改变自定义
    // checked(state, finds) {
    //   state.abcList.splice(finds, 1);
    // },
    // 获取到点击的颜色 并改变state里面的默认颜色
    setColor(state, payload) {
      state.color = payload;
    },
    // 获取body的点击颜色
    setBodyColor(state, payload) {
      state.bodycolor = payload;
    },

    //存储cat_id
    setId(state,payload){
      state.cat_id = payload
    },

    //存储订单价格
    setOrderPrice(state,payload){
      state.order_price = payload
    },

    //存储角色列表
    setUserRole(state,payload){
      state.role = payload
    },
  },

  // plugins: [createPersistedState()],   // 当前写法 会将 state 中的所有数据做本地存储
  // 本地存储 存储添加的数据
  plugins: [createPersistedState({
    reducer: (state) => {
      return {
        cat_id:state.cat_id,
        order_price:state.order_price,
      }
    }
  })],
  strict: true
})

export default store
